package com.example.backend.api.common;

import com.alibaba.druid.pool.DruidDataSource;
import java.sql.Connection;

public class DruidFactory {
    private static DruidDataSource dataSource = null;

    public static void init() throws Exception {

        dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("zzh0117.");//aliyun :zzh0117  windows:12345678
        dataSource.setUrl("jdbc:mysql://113.31.110.212:3306/db5?useUnicode=true&characterEncoding=utf-8");
        dataSource.setInitialSize(5);
        dataSource.setMinIdle(1);
        dataSource.setMaxActive(10);
    }

    public static Connection getConnection() throws Exception {
        if(null == dataSource)
        {
            init();
        }
        return dataSource.getConnection();
    }
}